﻿
@{
    ViewBag.Title = "_Add";
}
@using Shop.Entity;
@model TGoodsProperty
<link href="~/Content/checkbox/css/build.css" rel="stylesheet" />
<link href="~/Content/checkbox/Font-Awesome/css/font-awesome.min.css" rel="stylesheet" />
<div class="modal fade" id="Add" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="headerTitle">新增</h4>
            </div>
            <div class="modal-body">
                <div class="portlet-body form">
                    @using (Html.BeginForm("Save", "GoodsAttr", FormMethod.Post, new { id = "add", @class = "form-horizontal" }))
                    {

                        @Html.HiddenFor(c => c.Guid, new { @id = "Gid" })
                        @Html.HiddenFor(c => c.OperatorGuid)

                        <div class="form-body">
                            <div class="row">
                                <div class="form-group">
                                    <label class="control-label col-sm-3">
                                        名称
                                    </label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control input-sm input-inline" name="Name" id="Name" datatype="s2-6" nullmsg="请输入名称!" sucmsg=" " errormsg="名称至少1个字符,最多10个字符！" value="@Model.Name" />
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="form-group">
                                    <label class="control-label col-sm-3">
                                        所属分类
                                    </label>
                                    <div class="col-sm-5">
                                        @Html.DropDownListFor(c => c.GoodsCategoryGuid, (SelectList)ViewData["CateGory"], new { id = "Category", @class = "form-control input-sm" })
                                    </div>
                                </div>
                            </div>


                            <div class="row">
                                <div class="form-group">
                                    <label class="control-label col-sm-3">
                                        数据类型
                                    </label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-sm" name="dataType" id="dataType" onchange="DateTypeChange();">
                                            <option value="text">文本框</option>                                            
                                            <option value="option">下拉框</option>
                                            <option value="textArea">多行文本框</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group">
                                    <label class="control-label col-sm-3">
                                        默认值
                                    </label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control input-sm input-inline" name="DefaultValue" id="DefaultValue" value="@Model.DefaultValue" />
                                    </div>
                                </div>
                            </div>
                            <div class="row" style="display:none" id="divOption">
                                <div class="form-group">
                                    <label class="control-label col-sm-3">
                                        备选项
                                    </label>
                                    <div class="col-sm-6">
                                        <textarea class="form-control input-sm" rows="1" placeholder="请用'-'隔开" cols="20" id="Options" name="Options" ignore="ignore" datatype="*1-200" errormsg="不能超过200个字符!" sucmsg=" ">@Model.Options</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group">
                                    <label class="control-label col-sm-3">
                                        备注
                                    </label>
                                    <div class="col-sm-7">
                                        <textarea class="form-control input-sm" rows="3" cols="20" id="Remark" name="Remark" ignore="ignore" datatype="*1-300" errormsg="不能超过300个字符!" sucmsg=" ">@Model.Remark</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group">
                                    <label for="message-text" class="col-sm-2 control-label"></label>
                                    <div class="col-sm-7" id="tip">
                                        &nbsp;
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <input type="submit" class="btn btn-primary" value="保存" />
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    }
                </div>
            </div>

        </div>

    </div>
</div>

<script type="text/javascript">
    $('#Add').on('hidden.bs.modal', function (e) {
        layer.closeAll('tips'); //关闭所有的tips层
    })
    function ShowValidformMsg(msg, id) {
        layer.tips(msg, '#' + id, { tipsMore: true });
    }
    if ($("#Gid").val() == '@Guid.Empty') {
      
        $("#divOption").fadeOut();
    } else {
        $("#dataType").val('@Model.DataType');
        DateTypeChange();
    }

    function DateTypeChange() {
        if ($("#dataType").val() == "option") {
            $("#divOption").fadeIn();
        } else {
            $("#divOption").fadeOut();
        }
    }
    $(function () {
        $("#add").Validform({
            showAllError: true,
            ajaxPost: true,
            beforeSubmit: function (curform) {
                layer.msg('正在执行操作...', { icon: 16 });
                return true;
            },
            callback: function (data) {
                if (data.succ) {
                    layer.closeAll();
                    $('#Add').modal('hide');
                    parent.layer.msg(data.msg, { icon: 1 });

                    if ($(".pagination .active").find("a").html()!=undefined) {
                        $(".pagination .active").find("a").click();
                    } else {
                        $("#formSearch").submit();
                    }



                } else {
                    parent.layer.alert(data.msg);
                }
            },
            tiptype: function (msg, o) {
                if (msg.trim() != "" && o.type != 1)
                { ShowValidformMsg(msg, $(o.obj).attr("id")); }
            }
        }
        );
    })

</script>